

$("#classical").on('submit',function(){
    var formData=$(this).serialize();
    $.ajax({
        type:'post',
        url:'/categories',
        data:formData,
        success:function(){
            location.reload();
        }
    })
    return false;
});
$.ajax({
    type:'get',
    url:'/categories',
    success:function(res){
    var html=template('listTpl',{data:res});
        $("#categorybody").html(html);
    }
});

$("#categorybody").on('click',".edit",function(){
    var id = $(this).attr('data-id');
    $.ajax({
        type: 'get',
        url: "/categories/" + id,
        data: id,
        success: function (res) {
            var html = template('changeTpl', { res });
            $("#classEdit").html(html);
        }
    })
});


$("#classEdit").on('submit', '#fenlei', function () {
    var dormData = $(this).serialize();
    var id = $(this).attr('data-id');
    $.ajax({
        type: 'put',
        url: '/categories/' + id,
        data: dormData,
        success: function (res) {
            location.reload();
        }
    })
    return false;
});


$("#categorybody").on('click',".delete",function(){
    var id = $(this).attr('data-id');
    if (confirm("您真的要删除这个目录吗")) {
        $.ajax({
            type: 'delete',
            url: "/categories/" + id,
            data: id,
            success: function (res) {
                location.reload();
            }
        })
    }
    
});
